<?php
namespace Admin\Controller;
use Think\Controller;
class AuthController extends Controller {
    public function login(){
    	layout(false);		// 临时关闭当前模板的布局功能
       $this->display();
    }
    public function do_login(){
    	$rules = array(
			    array('username','require','用户名必填!'),
			    array('password','require','密码必填！'),
			);
		$admin_model = M("admin"); 
		if (!$admin_model->validate($rules)->create()){
		     $this->error($admin_model->getError());
		}else{
			$username=I('post.username');
			$password=md5(I('post.password'));
			if($admin=M('admin')->where(array(
				'username'=>$username,
				'password'=>$password
			))->find()){
				$_SESSION['admin_is_login']=true;
				$_SESSION['admin_username']=$username;
			}
    	}
    	$this->success('登录成功.',U('admin/Index/index'));
    }
    public function destroy(){
    	session('[destroy]');
    	$this->success('成功退出.','login');
    }
}